#include "customwidget.h"


#include <QStyleOption>
#include <QPainter>
#include <QPixmap>

#include <QPushButton>
#include <QLabel>
#include <QLineEdit>

#include <QHBoxLayout>
#include <QVBoxLayout>

#include <QMouseEvent>
#include <QShowEvent>

#include <QApplication>

#include <QPropertyAnimation>

CustomWidget::CustomWidget(QWidget *parent) : QWidget(parent)
{

}

void CustomWidget::paintEvent(QPaintEvent *)
{
    QStyleOption opt;
    opt.initFrom(this);//获取窗口的大小、位置、状态等信息,把这些信息记录到"装修方案"中
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

//////////////////////////////////////////////////////////////////////
/// \brief CustomMoveWidget::CustomMoveWidget
/// \param parent
/// 可移动窗体
CustomMoveWidget::CustomMoveWidget(QWidget *parent) :
    CustomWidget(parent)
{
#ifdef Q_OS_WIN32
    this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint);
#else
    this->setWindowFlags(Qt::FramelessWindowHint);
#endif
}

CustomMoveWidget::~CustomMoveWidget()
{

}
void CustomMoveWidget::mousePressEvent(QMouseEvent *e)
{
    if (e->button() == Qt::LeftButton) {
        m_mousePressed = true;
        mousePoint = e->globalPos() - this->pos();
        e->accept();
    }
}
void CustomMoveWidget::mouseMoveEvent(QMouseEvent *e)
{
    if (m_mousePressed && (e->buttons() & Qt::LeftButton)) {
        this->move(e->globalPos() - mousePoint);
        e->accept();

        // 主窗口特殊处理：保存位置
        // if ("MainWindow" == this->objectName()) {
        //     QPoint pos = e->globalPos() - mousePoint;

        // }
    }
}
void CustomMoveWidget::mouseReleaseEvent(QMouseEvent *)
{
    m_mousePressed = false;
}
